<template>
  <div class="TodoList">
    <table border="1">
      <thead>
        <tr>
          <th>标题</th>
          <th>状态</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="li in lists" :key="li.id">
          <td>{{ li.title }}</td>
          <td>{{ li.status }}</td>
          <td>
            <button @click="deleteList(li.id)">删除</button>
            <button>未完成</button>
            <button>进行中</button>
            <button>已完成</button>
          </td>
        </tr>
      </tbody>
    </table>
  </div>
</template>
<script>
import axios from 'axios';

const request = axios.create({
  baseURL: 'http://127.0.0.1:8081'
});
export default {
  data() {
    return {
      lists: [],
    };
  },

  created() {
    this.getLists();
  },
  methods: {
    async deleteList(id) {
      if (confirm('确定删除吗') === false) return;
      await request.delete(`/lists/${id}`);
      this.getLists();
    },
    async getLists(status = 0) {
      const where = {};
      if (status !== 0) {
        where.status = status;
      }
      const { data } = await request.get('/lists', {
        params: where,
      });
      this.lists = data;
    }
  }
};
</script>
<style></style>